using Unity.VisualScripting;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace LS.VisualScripting
{
    [UnitCategory("Lancer Studio")]
    public abstract class GFComponentUnit<TComponent> : Unit, IGFComponentUnit<TComponent> where TComponent : GameFrameworkComponent
    {
        protected virtual bool UseInput => true;
        protected virtual bool UseOutput => true;
        
        [PortLabelHidden]
        [DoNotSerialize]
        public ControlInput Input { get; private set; }
        
        [DoNotSerialize]
        [PortLabelHidden]
        public ControlOutput Output { get; private set; }

        [DoNotSerialize]
        public abstract TComponent Target { get; }

        protected override void Definition()
        {
            if (UseInput)
                Input = ControlInput(nameof(Input), In);
            
            if (UseOutput)
                Output = ControlOutput(nameof(Output));
            
            if(UseInput && UseOutput)
                Succession(Input, Output);
        }

        protected virtual ControlOutput In(Flow flow)
        {
            return Output;
        }
    }
}
